﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';
dbt = 'user_refundrequest';
</cfscript>
<cfparam name="UUID" default="0" type="string" >

<!---显示默认银行--->
<cffunction name="userdefaultbank" access="remote" returnFormat="json">
  <cfscript>
	j = {"success":"0"};
	</cfscript>
	<!---根据UUID查找ID--->
  <cfinvoke component="app.cfc.user" method="uuidgetuid" returnvariable="uuidgetuid" UUID="#uuid#"/>
  <cfif uuidgetuid.recordcount neq 1>
  	<!---,"msg":"用户ID错误"--->
    <cfset j = {"success":"0","errCode":"0"}>
  <cfelse>
  	<cfinvoke component="app.cfc.userbank" method="defaultbank" returnvariable="defaultbank" UID="#uuidgetuid.uid#"/>
	<!---可用保证金--->
<cfinvoke component="app.cfc.deposit" method="getbzjvalue" returnvariable="userdeposit" uid="#uuidgetuid.uid#" />
    <cfscript>
		if (defaultbank.recordcount gt 0){
			refund = {
				"aid":defaultbank.ubid,
				"bank":defaultbank.bank,
				"name":defaultbank.cardname,
				"card":defaultbank.cardno,
				"margin":userdeposit
			};
		}
		else {
			refund = {
				"aid":"0",
				"bank":"",
				"name":"",
				"card":"",
				"margin":"0"
			};
		}
		</cfscript>
		<cfscript>
    j = {"success":"1","refund":refund};
    </cfscript>
  </cfif>
  <cfscript>
	j = createObject("component",'cfjson').encode(j);
  return j;
	</cfscript>
</cffunction>


<!---提交余额退款接口--->
<cffunction name="refundrequest" access="remote" returnFormat="json">
  <cfscript>
	j = {"success":"0"};
	</cfscript>
	<!---根据UUID查找ID--->
  <cfinvoke component="app.cfc.user" method="uuidgetuid" returnvariable="uuidgetuid" UUID="#uuid#"/>
  <cfif uuidgetuid.recordcount neq 1>
  	<!--- "msg":"用户ID错误"--->
    <cfset j = {"success":"0","errCode":"0"}>
  <cfelse>
  	<cfparam name="remarks" default="" type="string">
  	<cfif isdefined('recharge') AND isdefined('aid')>
    	<cfif not isnumeric(recharge) or recharge lt 5>
				<cfscript>
				//"msg":"请填写正确的退款金额"
        j = {"success":"0","errCode":"-1"};
        </cfscript>
        
      <cfelseif not isnumeric(aid)>
				<cfscript>
				//,"msg":"请选择退款账号"
        j = {"success":"0","errCode":"-1"};
        </cfscript>
        
      <cfelse>
        <!---退款账号记录是否存在--->
        <cfinvoke component="app.cfc.userbank" method="showbank" returnvariable="showbank" uid="#uuidgetuid.uid#" ubid="#aid#" />
        <cfif showbank.recordcount eq 0>
					<cfscript>
					//,"msg":"没有找到你的银行账号信息"
          j = {"success":"0","errCode":"-1"};
          </cfscript>
          
        <cfelse>
        	<!---余额是否足够--->
          <cfinvoke component="app.cfc.recharge" method="getuserrecharge" returnvariable="getuserrecharge" uid="#uuidgetuid.uid#" />
          <cfif recharge gt getuserrecharge>
						<cfscript>
						//,"msg":"退款余额不足"
            j = {"success":"2","errCode":"-1"};
            </cfscript>
            
          <cfelse>
          	<!---正式申请--->
            <cfquery datasource="#DB#">
			<!---
            INSERT INTO user_refundrequest(uid,ubid,refund,user_note,dt,IP)
            VALUE(#uuidgetuid.uid#,#aid#,#recharge#,'#remarks#',#now()#,'#CGI.REMOTE_ADDR#')
			--->
			insert into user_account(payment_typeid,uid,amount,add_time,user_note,process_type,pay_province,pay_city,pay_bank,pay_cardno,pay_cardname,pay_mobile) values('chinapay',#uuidgetuid.uid#,#recharge#,#now()#,'#remarks#',1,'#showbank.province#','#showbank.city#','#showbank.bank#','#showbank.cardno#','#showbank.cardname#','#showbank.mobile#')
            </cfquery>
			<cfscript>
            j = {"success":"1"};
            </cfscript>
            
          </cfif>
          
        </cfif>
        
      </cfif>
    
    <cfelse>
			<cfscript>
			//,"msg":"缺少参数"
      j = {"success":"0","errCode":"-1"};
      </cfscript>
    
    </cfif>


  </cfif>
  <cfscript>
	j = createObject("component",'cfjson').encode(j);
  return j;
	</cfscript>
</cffunction>

<!---提交汇款告之--->
<cffunction name="remittanceinform" access="remote" returnFormat="json">
  <cfscript>
	j = {"success":"0"};
	//排错
	method = 'remittanceinform';
	</cfscript>
  <cfparam name="importaccount" default="" type="string">
  <cfparam name="bankinfo" default="" type="string">
  <cfparam name="type" default="银行划账" type="string">

	<!---根据UUID查找ID--->
  <cfinvoke component="app.cfc.user" method="uuidgetuid" returnvariable="uuidgetuid" UUID="#uuid#"/>
  <cfif uuidgetuid.recordcount neq 1>
  	<!---,"msg":"用户ID错误"--->
    <cfset j = {"success":"0","errCode":"0"}>
  <cfelse>
  	<cfparam name="remarks" default="" type="string">
  	<cfif isdefined('money') AND isdefined('date') AND isdefined('name') AND isdefined('info') AND isdefined('no')>
    	<cfif not isnumeric(money) or money lt 1>
				<cfscript>
				//,"msg":"请填写正确的汇款金额"
        j = {"success":"0","errCode":"-1"};
        </cfscript>
        
      <cfelse>

				<!---正式告之--->
        <cfquery datasource="#DB#">
        INSERT INTO user_remittanceinform(uid,deposittype,importaccount,bankinfo,deposit,deposit_dt,deposit_name,
        deposit_no,user_note,dt,IP)
        VALUE(#uuidgetuid.uid#,'#type#','#importaccount#','#bankinfo#',#money#,'#date#','#name#','#no#',
        '#remarks#',#now()#,'#CGI.REMOTE_ADDR#')
        </cfquery>
        <cfscript>
        j = {"success":"1"};
        </cfscript>
        
      </cfif>
    
    <cfelse>
			<cfscript>
			//,"msg":"缺少参数"
      j = {"success":"0","errCode":"-1"};
      </cfscript>
    
    </cfif>

  </cfif>
  <cfscript>
	j = createObject("component",'cfjson').encode(j);
  return j;
	</cfscript>
</cffunction>

</cfcomponent>